<template>
  <div class="container clearfix">
    <div class="header clearfix">
      <div class="search">
        <div class="searchTopBar">
          <SearchBar></SearchBar>
        </div>
      </div>
    </div>
    <!-- 主页 -->
    <div class="banner">
      <div class="left">
        <!-- <div class="leftItem"> -->
        <div
          class="text"
          v-for="l1 in categoryL1List"
          :key="l1.id"
          :class="{ active: currentId === l1.id }"
          @click="changeNavBtn(l1.id)"
        >
          <div class="name">{{ l1.name }}</div>
          <div class="textleft" :class="{ active: currentId === l1.id }"></div>
        </div>
      </div>

      <div class="right">
        <div class="rightBox">
          <img class="rightImg" :src="bannerImg" alt="" />
        </div>
        <div class="bannerItem" v-for="(item, index) in categoryL2List" :key="index">
          <div class="title">
            {{ item.name }}

            <hr />
          </div>

          <div class="main">
            <div class="mainList" v-for="(item1, index) in item.categoryList" :key="index">
              <img class="mainImg" :src="item1.wapBannerUrl" alt="" />
              <div class="text">{{ item1.name }}</div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <TabBar></TabBar>
  </div>
</template>
<script lang="ts">
import { defineComponent } from 'vue'
import { categoryImg } from './category'
export default defineComponent({
  name: 'Category'
})
</script>

<script lang="ts" setup>
import { onMounted } from 'vue'
import { setCategoryList } from '../../stores/category'
import { storeToRefs } from 'pinia'

const categoryStory = setCategoryList()
const { bannerImg, currentId, categoryL1List, categoryL2List } = storeToRefs(categoryStory)
onMounted(() => {
  categoryStory.getCategoryAsync()
  categoryStory.getCatgoryList(currentId.value)
})

const changeNavBtn = (id: number) => {
  currentId.value = id
  categoryStory.getCatgoryList(currentId.value)
}
</script>
<style lang="less" scoped>
.container {
  width: 100%;
  background-color: #fff;
}
.header {
  width: 100%;
  height: 44px;
  .search {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    .searchTopBar {
      width: 94%;
      padding: 10px 0;
      border-radius: 10px;
      box-sizing: border-box;
    }
  }
}

.banner {
  margin-top: 10px;
  height: 100%;
  width: 100%;
  border-top: 1px solid #ccc;
  display: flex;
  box-sizing: border-box;
  padding: 0 8px;

  .left {
    width: 68px;
    height: calc(100vh - 72px);
    .text {
      padding: 15px 0;
      height: 25px;
      width: 81px;
      font-size: 13px;
      line-height: 25px;
      position: relative;
      border-left: 1 px solid red;
      &.active {
        color: red;
      }
      .textleft {
        position: absolute;
        width: 3px;
        height: 15px;
        left: -14px;
        top: 20px;

        &.active {
          background-color: red;
        }
      }
    }
  }
  .right {
    width: calc(100vw - 68px);
    border-left: 1px solid #ccc;
    .rightBox {
      width: 264px;
      margin: 10px;
    }
    .rightImg {
      width: 100%;
      height: 96px;
    }
  }
  .title {
    font-size: 15px;
  }
  .tit {
    font-size: 14px;
    margin-left: 10px;
  }
  .title {
    margin-left: 10px;
    font-size: 15px;
  }
  .main {
    margin-top: 10px;
    width: 100%;
    height: 100%;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    .mainList {
      display: flex;
      width: 72px;
      height: 108px;
      margin: 0 10px;
      flex-direction: column;
    }
  }
  .mainImg {
    height: 35px;
    width: 35px;
  }
  .text {
    font-size: 13px;
  }
}
</style>
